package io.renren.modules.xiaoqu.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.utils.R;
import io.renren.modules.xiaoqu.entity.CostTypeEntity;
import io.renren.modules.xiaoqu.service.CostTypeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("xiaoqu/costType")
public class CostTypeController {
    @Autowired
    private CostTypeService costTypeService;

    @GetMapping("getList")
    public R getList(String type,int page,int pageSize){

        LambdaQueryWrapper<CostTypeEntity> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(type),CostTypeEntity::getType,type);
        Page<CostTypeEntity> pageUtil=new Page<>(page,pageSize);
        Page<CostTypeEntity> page1 = costTypeService.page(pageUtil, queryWrapper);


        return R.ok().put("data",page1);
    }

    @PostMapping("update")
    public R update(@RequestBody CostTypeEntity costTypeEntity){
        costTypeService.updateById(costTypeEntity);
        return R.ok();
    }

    @PostMapping("save")
    public R save(@RequestBody CostTypeEntity costTypeEntity){
        costTypeService.save(costTypeEntity);
        return R.ok();
    }

    @PostMapping("delete")
    public R delete(@RequestBody Long []ids){
        costTypeService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
}
